<template>
  <div
    id="aside-bottom"
    :class="{ hidden: !$store.state.playInfo.songData }"
    v-loading="isLoading">
    <img
      :src="imgUrl"
      @load="imgLoad"
      @click="showSongDetail">
    <div class="playInfo">
      <div class="name">{{ playInfoName }}</div>
      <div class="singer" v-if="$store.state.playInfo.songData">
        <span
          v-for="(item, index) in $store.state.playInfo.songData.ar"
          :key="index">
          {{ item.name }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import types from 'utils/types.js'

export default {
  name: 'AsideBottom',
  data () {
    return {
      isLoading: true
    }
  },
  computed: {
    // 1. 图片url
    imgUrl () {
      return this.$store.state.playInfo.songData && this.$store.state.playInfo.songData.al.picUrl
    },
    // 2. 歌曲名字
    playInfoName () {
      return this.$store.state.playInfo.songData && this.$store.state.playInfo.songData.name
    }
  },
  methods: {
    // 1. 图片加载完成
    imgLoad () {
      setTimeout(() => {
        this.isLoading = false
      }, 0)
    },
    // 2. 打开歌曲详情页
    showSongDetail () {
      this.$store.commit(types.SHOW_SONG_DETAIL)
    }
  },
  watch: {
    imgUrl () {
      this.isLoading = true
    }
  }
}
</script>

<style scoped lang="less">
#aside-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--aside--bottom--height);
  border-top: 1px solid #e1e1e2;
  padding: 6px;
  display: flex;
  img {
    height: 100%;
    width: calc(var(--aside--bottom--height) - 12px);
    border: 1px solid #e5e5e5;
    cursor: pointer;
  }
  .playInfo {
    padding-left: 10px;
    width: 130px;
    > div {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .name {
      margin-top: 5px;
      font-size: 13px;
      color: #333;
    }
    .singer {
      width: 80px;
      margin-top: 5px;
      font-size: 13px;
      color: #666;
      span {
        position: relative;
        margin-right: 4px;
        &:nth-last-of-type(n+2):after {
          position: absolute;
          right: -3px;
          content: "/";
        }
      }
    }
  }
}
</style>

<style lang="less">
#aside-bottom {
  .el-loading-mask {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #f5f5f7;
  }
}
</style>
